package controller.webservice.bootstrap;

import java.io.IOException;

import manager.CoursePreRequisiteMgr;
import controller.validator.PreRequisiteValidator;
import exception.InputValidationErrors;

/**
 * Validates and loads prerequisite CSV.
 * 
 * @author huangjm.2012, jaslin.wee.2012, sheryl.tay.2012
 * 
 */
public class PreRequisiteCsvLoader extends CsvLoader {

	private CoursePreRequisiteMgr coursePreRequisiteMgr;

	PreRequisiteCsvLoader(String pathToFile) throws IOException {
		super(pathToFile);
		coursePreRequisiteMgr = new CoursePreRequisiteMgr();
	}

	@Override
	boolean loadRow() throws InputValidationErrors {

		String courseCode = getValue("course");
		String preRequisiteCode = getValue("prerequisite");

		PreRequisiteValidator validator = new PreRequisiteValidator(
				preRequisiteCode, courseCode);
		validator.performValidationBeforeAdding();

		return coursePreRequisiteMgr.addPreRequisiteForCourse(
				validator.getPreRequisiteCode(), validator.getCourseCode());

	}

}
